#ifndef CCLABELTTF_EXT_H
#define CCLABELTTF_EXT_H
#include "cocos2d.h"

using namespace cocos2d;


class CCLabelTTF_Ext : public CCNode , public CCRGBAProtocol
{
public:
    CCLabelTTF * mlabel;

	std::string *m_string;
    std::string *m_fontName;

	CCLabelTTF_Ext(char * string ,char * fontname ,int fontSize):mlabel(0)
	{
		m_string = new std::string(string);
		setFontName(fontname);
		setFontSize(fontSize);
		recreateLabel();
		autorelease();
	}

	~CCLabelTTF_Ext()
	{
		CC_SAFE_DELETE(m_string)
		CC_SAFE_DELETE(m_fontName)
	}

	void setString(const char * string){
		mlabel->setString(string);
		this->setContentSize(mlabel->getContentSize());
		m_string = new std::string(string);
	}
	const char * getString(void){return m_string->c_str();}

	void setFontName(const char * fontname){m_fontName = new std::string(fontname);}
	const char * fontName(void){return m_fontName->c_str();}


    virtual void setColor(const ccColor3B& color) 
	{
		mlabel->setColor(color);
	}


	virtual const ccColor3B& getColor(void) 
	{
		return mlabel->getColor();
	}


    virtual GLubyte getOpacity(void)
	{
		return mlabel->getOpacity();
	}

	virtual void setOpacity(GLubyte opacity) 
	{
		mlabel->setOpacity(opacity);
	}

	virtual void setIsOpacityModifyRGB(bool bValue) {}

	virtual bool getIsOpacityModifyRGB(void) {return false;}
 
    void recreateLabel()
    {
		ccColor3B color = {255 ,255,255};
		int alpha = 255;
		if (mlabel !=NULL)
		{
				color = mlabel->getColor();
				alpha = mlabel->getOpacity();
				mlabel->removeFromParentAndCleanup(true);
		}

        mlabel = CCLabelTTF::labelWithString(m_string->c_str() , m_fontName->c_str()  , m_fontSize);
		mlabel->setColor(color);
		mlabel->setOpacity(alpha);
		this->addChild(mlabel);
		this->setContentSize(mlabel->getContentSize());
		mlabel->setAnchorPoint(ccp(0,0));
    }


	CC_SYNTHESIZE_PASS_BY_REF(int , m_fontSize, FontSize)
    
};

#endif // CCLABELTTF_EXT_H
